import Vue, { provide } from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {},
		systemInfo: {}
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: provider  
			}) 
			console.log(state.userInfo);
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({  
                key: 'userInfo'  
            })
		},
		setSystemInfo(state,provider) {
			state.systemInfo = provider
		}
	},
	actions: {
		goBack() {
		  uni.navigateBack({
			delta: 1 ,// 返回上一级页面
			success() {
				console.log("navigate back success");
			},
			fail(err) {
				console.log(JSON.stringify(err));
				uni.switchTab({
					url:"/pages/index/index"
				})
			}
		  });
		}
	}
})

export default store
